﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Linq;

namespace QuanLyKTX
{
    using DAL;
    public partial class frm_ReportContractViewer : Telerik.WinControls.UI.RadForm
    {
        public tbl_SinhVien SinhVien { get; set; }
        public tbl_HopDong HopDong { get; set; }

        public frm_ReportContractViewer(tbl_SinhVien sinhVien, tbl_HopDong hopDong)
        {
            InitializeComponent();
            SinhVien = sinhVien;
            HopDong = hopDong;
        }

        private void frm_ReportContractViewer_Load(object sender, EventArgs e)
        {
           string tenKhoa = "";
           string tenTruong = "";
           using (var db = new QuanLyKTXDataContext())
           {
               var khoa = (from l in db.tbl_Lops join k in db.tbl_Khoas on l.MaKhoa equals k.MaKhoa where l.MaLop == SinhVien.MaLop select k.TenKhoa).FirstOrDefault();
               tenKhoa = khoa;

               var truong = (from p in db.tbl_Truongs
                             join q in db.tbl_SinhViens on p.MaTruong equals q.MaTruong
                             where p.MaTruong == SinhVien.MaTruong
                             select p).FirstOrDefault();
               tenTruong = truong.TenTruong.Trim();
           }
            DataRow dr = dataSetHopDong.Tables[0].NewRow();
            dr["MaSinhVien"] = SinhVien.MaSinhVien;
            dr["MaLop"] = SinhVien.MaLop;
            dr["Khoa"] = tenKhoa;
            dr["HoTen"] = String.Format("{0} {1}", SinhVien.Ho, SinhVien.Ten);
            dr["SoCMND"] = SinhVien.SoCMND;
            dr["NoiCap"] = SinhVien.NoiCap;
            if (SinhVien.NgayCap != null)
                dr["NgayCap"] = SinhVien.NgayCap;
            dr["DiaChi"] = SinhVien.DiaChi;
            dr["SoDienThoai"] = SinhVien.SoDienThoai;
            dr["NgayKetThucHD"] = HopDong.NgayKetThucHD;
            dr["TienPhong"] = HopDong.TienPhong;
            dr["TienPhongVL"] = HopDong.TienPhongVL;
            dr["PhiBanDau"] = HopDong.PhiBanDau;
            dr["PhiBanDauVL"] = HopDong.PhiBanDauVL;
            dr["MienGiam"] = HopDong.MienGiam;
            dr["KyHan"] = HopDong.KyHan;
            dr["SoHopDong"] = String.Format("{0}/{1}",HopDong.SoHopDong.ToString(),HopDong.HauTo);
            dr["Truong"] = tenTruong;
            
            dataSetHopDong.Tables[0].Rows.Add(dr);

            if (HopDong.LoaiHopDong == 2)
                reportViewer_HopDong.LocalReport.ReportEmbeddedResource = "QuanLyKTX.Report.rpt_ContractsAll.rdlc";
            else
                reportViewer_HopDong.LocalReport.ReportEmbeddedResource = "QuanLyKTX.Report.rpt_Contracts.rdlc";
            reportViewer_HopDong.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet_HopDong", dataSetHopDong.Tables[0]));
            reportViewer_HopDong.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer_HopDong.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
            reportViewer_HopDong.RefreshReport();

        }
    }
}
